var hystrVar = "";
hystrVar += "<div  class=\"aui_state_box\"><div class=\"aui_state_box_bg\"></div>";
hystrVar += "<div class=\"aui_outer aui_alert\" id=\"drag_con\">";
hystrVar += "<table class=\"aui_border aui_hybox\" style=\"border:2px solid #8a9499;\">";
hystrVar += "<tbody>";
hystrVar += "<tr>";
hystrVar += "	<td class=\"aui_w\">";
hystrVar += "	</td>";
hystrVar += "	<td class=\"aui_c\">";
hystrVar += "		<div class=\"aui_inner\">";
hystrVar += "			<table class=\"aui_dialog\">";
hystrVar += "			<tbody>";
hystrVar += "			<tr>";
hystrVar += "				<td class=\"aui_header\" colspan=\"2\">";
hystrVar += "					<div class=\"aui_titleBar\">";
hystrVar += "						<div class=\"aui_title\" style=\"cursor: move;\">";
hystrVar += "							选择行业分类1";
hystrVar += "						</div>";
hystrVar += "						<a href=\"javascript:;\" class=\"aui_close\" onclick=\"Close()\">×</a>";
hystrVar += "					</div>";
hystrVar += "				</td>";
hystrVar += "			</tr>";
hystrVar += "			<tr>";
hystrVar += "				<td class=\"aui_icon\" style=\"display: none;\">";
hystrVar += "					<div class=\"aui_iconBg\" style=\"background: transparent none repeat scroll 0% 0%;\">";
hystrVar += "					</div>";
hystrVar += "				</td>";
hystrVar += "				<td class=\"aui_main\" style=\"width: auto; height: auto;\">";
hystrVar += "					<div class=\"aui_content\" style=\"padding: 10px 25px;\">";
hystrVar += "						<div class=\"items jquery-localdata\">";
hystrVar += "							<div style=\"height:400px\" class=\"item-table\">";
hystrVar += "								<table style=\"width:700px;\" class=\"options-table\">";
hystrVar += "								<tbody class=\"item-list\" id=\"industy_tc\">";
hystrVar += "								</tbody>";
hystrVar += "								</table>";
hystrVar += "							</div>";
hystrVar += "						</div>";
hystrVar += "					</div>";
hystrVar += "				</td>";
hystrVar += "			</tr>";
hystrVar += "			<tr>";
hystrVar += "				<td class=\"aui_footer\" colspan=\"2\">";
hystrVar += "					<div class=\"aui_buttons\">";
hystrVar += "						<button class=\"aui-btn aui-btn-primary\" type=\"button\" onclick=\"svae_hyitem()\">确定</button>";
hystrVar += "						<button class=\"aui-btn aui-btn-light\" type=\"button\" onclick=\"Close()\">取消</button>";
hystrVar += "					</div>";
hystrVar += "				</td>";
hystrVar += "			</tr>";
hystrVar += "			</tbody>";
hystrVar += "			</table>";
hystrVar += "		</div>";
hystrVar += "	</td>";
hystrVar += "	<td class=\"aui_e\">";
hystrVar += "	</td>";
hystrVar += "</tr>";
hystrVar += "<tr>";
hystrVar += "	<td class=\"aui_sw\">";
hystrVar += "	</td>";
hystrVar += "	<td class=\"aui_s\">";
hystrVar += "	</td>";
hystrVar += "	<td class=\"aui_se\" style=\"cursor: se-resize;\">";
hystrVar += "	</td>";
hystrVar += "</tr>";
hystrVar += "</tbody> </table></div></div>";
// 多选
var datainput = null;
var zytype = "";
function appendhybar(thiscon, type) {
	datainput = thiscon;
	zytype = type;
	$('.check_info').append(hystrVar);
	
	var csrf_token = $("#csrf_token").val();
	var industry_url = $("#industry_url").val();
	var industry_data = {};
    $.ajax({
         cache: false,
         async: false,
         dataType: 'json', 
         data: '_token='+csrf_token+'&is_ajax=1',
         type: 'get',
         url:industry_url,
         success: function (response){
        	 industry_data = response.data;
         }
    });
   
    
    var industy_html = '';
    for ( var i in industry_data) {
    	var node = "";
    	for ( var j in industry_data[i].list) {
    		if (j != industry_data[i].list.length - 1) {
    			if (j % 2 == 0) {
    				node += "		<tr>";
    				node += "			<td>";
    				node += "				<label>";
    				node += "				<input type=\"checkbox\"  name=\"item-list\" class=\"input-checkbox\" data-value=\"" + industry_data[i].list[j].id + "\" data-name=\"" + industry_data[i].list[j].title + "\"  onclick=\"addhyitem(this)\" >";
    				node += industry_data[i].list[j].title;
    				node += "				</label>";
    				node += "			</td>";
    			} else {
    				node += "			<td>";
    				node += "				<label>";
    				node += "				<input type=\"checkbox\"  name=\"item-list\" class=\"input-checkbox\" data-value=\"" + industry_data[i].list[j].id + "\" data-name=\"" + industry_data[i].list[j].title + "\"  onclick=\"addhyitem(this)\">";
    				node += industry_data[i].list[j].title;
    				node += "				</label>";
    				node += "			</td>";
    				node += "		</tr>";
    			}
    		} else {
    			if (j / 2 == 0) {
    				node += "		<tr>";
    				node += "			<td>";
    				node += "				<label>";
    				node += "				<input type=\"checkbox\"  name=\"item-list\" class=\"input-checkbox\" data-value=\""+ industry_data[i].list[j].id + "\" data-name=\"" + industry_data[i].list[j].title + "\"  onclick=\"addhyitem(this)\">";
    				node += industry_data[i].list[j].title;
    				node += "				</label>";
    				node += "			</td>";
    				node += "		</tr>";
    			} else {
    				node += "			<td>";
    				node += "				<label>";
    				node += "				<input type=\"checkbox\"  name=\"item-list\" class=\"input-checkbox\" data-value=\"" + industry_data[i].list[j].id + "\" data-name=\"" + industry_data[i].list[j].title + "\"  onclick=\"addhyitem(this)\">";
    				node += industry_data[i].list[j].title;
    				node += "				</label>";
    				node += "			</td>";
    				node += "		</tr>";
    			}
    		}

    	}
    	industy_html += "<tr>";
    	industy_html += "	<th width=\"150\">";
    	industy_html += industry_data[i].title;
    	industy_html += "	</th>";
    	industy_html += "	<td>";
    	industy_html += "		<table>";
    	industy_html += "		<tbody>";
    	industy_html += node;
    	industy_html += "		</tbody>";
    	industy_html += "		</table>";
    	industy_html += "	</td>";
    	industy_html += "</tr>";
    }
    
    $("#industy_tc").html(industy_html)
	
	if (zytype == "duoxuan") {
		if ($(datainput).data("value") != '') {
			var inputarry = String($(datainput).data("value")).split(',');
			$('.options-table .input-checkbox').each(function(index) {
				for ( var i in inputarry) {
					if ($(this).data("value") == inputarry[i]) {
						$(this).click();
					}
				}
			});
		}
	} else {
		$('.aui_state_box .aui_buttons').remove();
		$('.aui-titlespan').remove();
	}

//	var minwid = document.documentElement.clientWidth;
//	$('.aui_outer').on("mousedown",function(e) {
//		$(this)[0].onselectstart = function(e) {
//			alert(11);
//			return false; 
//		}
//		// 防止拖动窗口时，会有文字被选中的现象(事实证明不加上这段效果会更好)
//		$(this)[0].oncontextmenu = function(e) {
//			alert(1);
//			return false;
//		}
//		// 防止右击弹出菜单
//		var getStartX = e.pageX, getStartY = e.pageY;
//		var getPositionX = (minwid / 2) - $(this).offset().left, getPositionY = $(this).offset().top;
//		$(document).on("mousemove", function(e) {
//			var getEndX = e.pageX, getEndY = e.pageY;
//			$('.aui_outer').css({
//				left : getEndX - getStartX - getPositionX,
//				top : getEndY - getStartY + getPositionY
//			});
//
//		});
//		$(document).on("mouseup", function() {
//			$(document).unbind("mousemove");
//		})
//	});
}
//选择行业
function addhyitem(con){
	if($('.options-table .input-checkbox:checked').length > 3){
		$(con).prop("checked",false);
		alert('最多只能选择3项！'); return false;
	}
}


// 确定选择
function svae_hyitem() {
	var val = '';
	var valname = '';
	var industry_list = '';
	$('.options-table .input-checkbox').each(function(index) {
		if($(this).is(':checked')){
			val += $(this).data("value") + ',';
			valname += $(this).data("name") + '-';
//			industry_list += '<input name="industry[]" value="'+$(this).data("value")+'" data-name="'+$(this).data("name")+'" type="hidden">';
		}
	});
	
	if (val != '') {
		val = val.substring(0, val.lastIndexOf(','));
	}
	if (valname != '') {
		valname = valname.substring(0, valname.lastIndexOf('-'));
	}
	$(datainput).data("value", val);
	$(datainput).val(valname);
//	$("#industry_list").html(industry_list);

	$('.aui_state_box').remove();
}
function Close() {
	$('.aui_state_box').remove();
}


